package com.example.javabasic.thread.classtwo.countdown.demo2;

public class CountDown {
    private final int total;
    //计数器
    private int counter;

    public CountDown(int total) {
        this.total = total;
    }

    public void down(){
        synchronized (this){
            this.counter++;
            this.notifyAll();
        }
    }
    public void await(){
        synchronized (this){
            while(counter!=total){
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
